package com.fau.om.util;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;

/**
 * @desc 下载时文件名转码工具类
 * @author liy
 * @datetime 2015年1月6日,上午10:42:46
 */
public class FileNameEncoderUtil {
	
	/**
	 * @desc 将文件名转码
	 * @return String
	 * @author liy
	 * @throws IOException 
	 * @datetime 2015年1月6日,上午10:44:04
	 */
	public static String encode(HttpServletRequest request, String fileName) throws IOException {
		String finalFileName = null;
		String agent = request.getHeader("User-Agent");
		
        boolean isMSIE = (agent != null && (agent.indexOf("MSIE") != -1 || agent.indexOf("like Gecko") != -1));
        
        if( isMSIE ){
             
				finalFileName = URLEncoder.encode(fileName,"UTF8");
        }else{
            finalFileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
        }
        return finalFileName;
	}
}
